Kernel: .venv
MINIMUM SET COVER / Минимальное покрытие множеств
In [1]:
In [2]:
Постановка задачи
Представим, что мы имеем конечное множество «U» (universum) и «S» — список подмножеств множества «U».
'''Покрытием''' называют семейство наименьшей мощности, объединением которых является . В случае постановки вопроса '''о разрешении''' на вход подаётся пара и целое число k; вопросом является существование покрывающего множества мощности k (или менее).
Оптимизационная версия задачи, '''минимальное покрытие множеств''', задаёт вопрос о минимальном числе множеств из «S» покрывающих «U».
In [3]:
In [4]:
Реализация в Pyomo
In [5]:
In [6]:
(['01',
'02',
'03',
'04',
'05',
'06',
'07',
'08',
'09',
'10',
'11',
'12',
'13',
'14',
'15',
'16',
'17',
'18'],
[{'01', '02', '03', '04', '05', '06', '07', '08', '09', '10'},
{'01', '02', '04', '06', '08', '10', '12', '14', '16', '18'},
{'03'},
{'04', '11'},
{'09', '11', '16'},
{'03', '04', '17'},
{'02', '03', '07', '10', '18'},
{'09', '10', '12', '13', '15', '16'},
{'03', '05', '06', '08', '12', '17'},
{'01', '04', '06', '07', '11', '14', '18'},
{'01', '04', '05', '12', '13', '15', '17'}])
In [7]:
2 Set Declarations
x_index : Size=1, Index=None, Ordered=Insertion
Key : Dimen : Domain : Size : Members
None : 1 : Any : 11 : {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
каждый_элемент_в_одном_множестве_index : Size=1, Index=None, Ordered=Insertion
Key : Dimen : Domain : Size : Members
None : 1 : Any : 18 : {'01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18'}
1 Var Declarations
x : Size=11, Index=x_index
Key : Lower : Value : Upper : Fixed : Stale : Domain
0 : 0 : None : 1 : False : True : Binary
1 : 0 : None : 1 : False : True : Binary
2 : 0 : None : 1 : False : True : Binary
3 : 0 : None : 1 : False : True : Binary
4 : 0 : None : 1 : False : True : Binary
5 : 0 : None : 1 : False : True : Binary
6 : 0 : None : 1 : False : True : Binary
7 : 0 : None : 1 : False : True : Binary
8 : 0 : None : 1 : False : True : Binary
9 : 0 : None : 1 : False : True : Binary
10 : 0 : None : 1 : False : True : Binary
1 Objective Declarations
set_count : Size=1, Index=None, Active=True
Key : Active : Sense : Expression
None : True : minimize : x[0] + x[1] + x[2] + x[3] + x[4] + x[5] + x[6] + x[7] + x[8] + x[9] + x[10]
1 Constraint Declarations
каждый_элемент_в_одном_множестве : Size=18, Index=каждый_элемент_в_одном_множестве_index, Active=True
Key : Lower : Body : Upper : Active
01 : 1.0 : x[0] + x[1] + x[9] + x[10] : +Inf : True
02 : 1.0 : x[0] + x[1] + x[6] : +Inf : True
03 : 1.0 : x[0] + x[2] + x[5] + x[6] + x[8] : +Inf : True
04 : 1.0 : x[0] + x[1] + x[3] + x[5] + x[9] + x[10] : +Inf : True
05 : 1.0 : x[0] + x[8] + x[10] : +Inf : True
06 : 1.0 : x[0] + x[1] + x[8] + x[9] : +Inf : True
07 : 1.0 : x[0] + x[6] + x[9] : +Inf : True
08 : 1.0 : x[0] + x[1] + x[8] : +Inf : True
09 : 1.0 : x[0] + x[4] + x[7] : +Inf : True
10 : 1.0 : x[0] + x[1] + x[6] + x[7] : +Inf : True
11 : 1.0 : x[3] + x[4] + x[9] : +Inf : True
12 : 1.0 : x[1] + x[7] + x[8] + x[10] : +Inf : True
13 : 1.0 : x[7] + x[10] : +Inf : True
14 : 1.0 : x[1] + x[9] : +Inf : True
15 : 1.0 : x[7] + x[10] : +Inf : True
16 : 1.0 : x[1] + x[4] + x[7] : +Inf : True
17 : 1.0 : x[5] + x[8] + x[10] : +Inf : True
18 : 1.0 : x[1] + x[6] + x[9] : +Inf : True
5 Declarations: x_index x set_count каждый_элемент_в_одном_множестве_index каждый_элемент_в_одном_множестве
In [8]:
# ==========================================================
# = Solver Results =
# ==========================================================
# ----------------------------------------------------------
# Problem Information
# ----------------------------------------------------------
Problem:
- Name: unknown
Lower bound: 4.0
Upper bound: 4.0
Number of objectives: 1
Number of constraints: 17
Number of variables: 11
Number of binary variables: 11
Number of integer variables: 11
Number of nonzeros: 11
Sense: minimize
# ----------------------------------------------------------
# Solver Information
# ----------------------------------------------------------
Solver:
- Status: ok
User time: -1.0
System time: 0.01
Wallclock time: 0.01
Termination condition: optimal
Termination message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.
Statistics:
Branch and bound:
Number of bounded subproblems: 0
Number of created subproblems: 0
Black box:
Number of iterations: 0
Error rc: 0
Time: 0.5427391529083252
# ----------------------------------------------------------
# Solution Information
# ----------------------------------------------------------
Solution:
- number of solutions: 0
number of solutions displayed: 0
x[0] 1.0
x[7] 1.0
x[9] 1.0
x[10] 1.0
In [9]:
x[0] 1.0
x[7] 1.0
x[9] 1.0
x[10] 1.0
In [10]:
[0, 7, 9, 10]
In [11]:
In [ ]:
In [12]:
[(-3, -1, -2), (2, 3, -1), (-2, 1, 3), (1, 2, 3), (3, -2, -1)]
In [13]:
True
In [14]:
[1, -2, 3]
| | |
In [15]:
In [16]:
({1, 2, 3}, [{2, 4, 6}, {2, 3, 5}, {1, 4, 5}, {1, 3, 5}, {2, 4, 5}], 5)
In [17]:
[(-3, -1, -2), (2, 3, -1), (-2, 1, 3), (1, 2, 3), (3, -2, -1)]
In [18]:
In [19]:
[[1, -2, 3], [-1, -2, 3], [-1, 2, 3]]
In [20]:
In [21]:
[(3, -1, -2)]
In [22]:
{'x_{1}=0': ['x_{1}', 'C_{0}'],
'x_{1}=1': ['x_{1}'],
'x_{2}=0': ['x_{2}', 'C_{0}'],
'x_{2}=1': ['x_{2}'],
'x_{3}=0': ['x_{3}'],
'x_{3}=1': ['x_{3}', 'C_{0}']}
In [23]:
In [24]:
(['C_{0}', 'x_{1}', 'x_{2}', 'x_{3}'],
[{'C_{0}', 'x_{1}'},
{'x_{1}'},
{'C_{0}', 'x_{2}'},
{'x_{2}'},
{'x_{3}'},
{'C_{0}', 'x_{3}'}])
In [25]:
# ==========================================================
# = Solver Results =
# ==========================================================
# ----------------------------------------------------------
# Problem Information
# ----------------------------------------------------------
Problem:
- Name: unknown
Lower bound: 3.0
Upper bound: 3.0
Number of objectives: 1
Number of constraints: 4
Number of variables: 6
Number of binary variables: 6
Number of integer variables: 6
Number of nonzeros: 6
Sense: minimize
# ----------------------------------------------------------
# Solver Information
# ----------------------------------------------------------
Solver:
- Status: ok
User time: -1.0
System time: 0.01
Wallclock time: 0.01
Termination condition: optimal
Termination message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.
Statistics:
Branch and bound:
Number of bounded subproblems: 0
Number of created subproblems: 0
Black box:
Number of iterations: 0
Error rc: 0
Time: 0.07667303085327148
# ----------------------------------------------------------
# Solution Information
# ----------------------------------------------------------
Solution:
- number of solutions: 0
number of solutions displayed: 0
x[1] 1.0
x[3] 1.0
x[5] 1.0
In [26]:
[1, 3, 5]
In [27]:
[(3, -1, -2)]
In [28]:
{'x_{1}=0': ['x_{1}', 'C_{0}'],
'x_{1}=1': ['x_{1}'],
'x_{2}=0': ['x_{2}', 'C_{0}'],
'x_{2}=1': ['x_{2}'],
'x_{3}=0': ['x_{3}'],
'x_{3}=1': ['x_{3}', 'C_{0}']}
In [29]:
In [ ]:
In [30]:
[(-3, 2, 1), (3, 1, 2)]
In [31]:
{'x_{1}=0': ['x_{1}'],
'x_{1}=1': ['x_{1}', 'C_{0}', 'C_{1}'],
'x_{2}=0': ['x_{2}'],
'x_{2}=1': ['x_{2}', 'C_{0}', 'C_{1}'],
'x_{3}=0': ['x_{3}', 'C_{0}'],
'x_{3}=1': ['x_{3}', 'C_{1}']}
In [32]:
In [33]:
(['C_{0}', 'C_{1}', 'x_{1}', 'x_{2}', 'x_{3}'],
[{'x_{1}'},
{'C_{0}', 'C_{1}', 'x_{1}'},
{'x_{2}'},
{'C_{0}', 'C_{1}', 'x_{2}'},
{'C_{0}', 'x_{3}'},
{'C_{1}', 'x_{3}'}])
In [34]:
# ==========================================================
# = Solver Results =
# ==========================================================
# ----------------------------------------------------------
# Problem Information
# ----------------------------------------------------------
Problem:
- Name: unknown
Lower bound: 3.0
Upper bound: 3.0
Number of objectives: 1
Number of constraints: 5
Number of variables: 6
Number of binary variables: 6
Number of integer variables: 6
Number of nonzeros: 6
Sense: minimize
# ----------------------------------------------------------
# Solver Information
# ----------------------------------------------------------
Solver:
- Status: ok
User time: -1.0
System time: 0.01
Wallclock time: 0.0
Termination condition: optimal
Termination message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.
Statistics:
Branch and bound:
Number of bounded subproblems: 0
Number of created subproblems: 0
Black box:
Number of iterations: 0
Error rc: 0
Time: 0.040219783782958984
# ----------------------------------------------------------
# Solution Information
# ----------------------------------------------------------
Solution:
- number of solutions: 0
number of solutions displayed: 0
x[1] 1.0
x[2] 1.0
x[5] 1.0
In [35]:
[1, 2, 5]
In [36]:
[(-3, 2, 1), (3, 1, 2)]
In [37]:
{'x_{1}=0': ['x_{1}'],
'x_{1}=1': ['x_{1}', 'C_{0}', 'C_{1}'],
'x_{2}=0': ['x_{2}'],
'x_{2}=1': ['x_{2}', 'C_{0}', 'C_{1}'],
'x_{3}=0': ['x_{3}', 'C_{0}'],
'x_{3}=1': ['x_{3}', 'C_{1}']}
In [38]:
In [39]:
2 Set Declarations
x_index : Size=1, Index=None, Ordered=Insertion
Key : Dimen : Domain : Size : Members
None : 1 : Any : 6 : {0, 1, 2, 3, 4, 5}
каждый_элемент_в_одном_множестве_index : Size=1, Index=None, Ordered=Insertion
Key : Dimen : Domain : Size : Members
None : 1 : Any : 5 : {'C_{0}', 'C_{1}', 'x_{1}', 'x_{2}', 'x_{3}'}
1 Var Declarations
x : Size=6, Index=x_index
Key : Lower : Value : Upper : Fixed : Stale : Domain
0 : 0 : 0.0 : 1 : False : False : Binary
1 : 0 : 1.0 : 1 : False : False : Binary
2 : 0 : 1.0 : 1 : False : False : Binary
3 : 0 : 0.0 : 1 : False : False : Binary
4 : 0 : 0.0 : 1 : False : False : Binary
5 : 0 : 1.0 : 1 : False : False : Binary
1 Objective Declarations
set_count : Size=1, Index=None, Active=True
Key : Active : Sense : Expression
None : True : minimize : x[0] + x[1] + x[2] + x[3] + x[4] + x[5]
1 Constraint Declarations
каждый_элемент_в_одном_множестве : Size=5, Index=каждый_элемент_в_одном_множестве_index, Active=True
Key : Lower : Body : Upper : Active
C_{0} : 1.0 : x[1] + x[3] + x[4] : +Inf : True
C_{1} : 1.0 : x[1] + x[3] + x[5] : +Inf : True
x_{1} : 1.0 : x[0] + x[1] : +Inf : True
x_{2} : 1.0 : x[2] + x[3] : +Inf : True
x_{3} : 1.0 : x[4] + x[5] : +Inf : True
5 Declarations: x_index x set_count каждый_элемент_в_одном_множестве_index каждый_элемент_в_одном_множестве
['C_{0}', 'C_{1}', 'x_{1}', 'x_{2}', 'x_{3}']
In [ ]: